package com.crl.net
{
	import com.crl.core.crl_internal;
	import com.crl.events.RemoteEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.ProgressEvent;
	import flash.utils.ByteArray;

	use namespace crl_internal;
	public class ResourceToken extends EventDispatcher
	{
		crl_internal var _stopHandler:Function;
		
		/**
		 * 资源类型; 
		 */		
		crl_internal var _type:int;
		
		/**
		 * 具体数据 
		 */		
		crl_internal var _data:*;
		
		/**
		 * 当前状态; 
		 */		
		crl_internal var _status:int;
	
		
		public function ResourceToken()
		{
		}
		
		public function get type():int{
			return _type;
		}
		
		public function get status():int{
			return _status;
		}
		
		public function get data():*{
			return _data;
		}
		
		
		public function stop():void{
			if(_stopHandler!=null){
				_stopHandler();
			}
		}
		
		public function dispatchSuccessed(data:*):Boolean{
			_data=data;
			
			var event:RemoteEvent;
			if(hasEventListener(RemoteEvent.SUCCESED)==false){
				return false;
			}
			event=new RemoteEvent(RemoteEvent.SUCCESED,data);
			return this.dispatchEvent(event);
		}
		
		public function dispatchFailed(errorEvent:Event):Boolean{
			var event:RemoteEvent;
			if(hasEventListener(RemoteEvent.FAILED)==false){
				return false;
			}
			event=new RemoteEvent(RemoteEvent.FAILED,errorEvent);
			return this.dispatchEvent(event);
		}
		
		public function dispatchProgress(event:ProgressEvent):Boolean{
			if(hasEventListener(ProgressEvent.PROGRESS)==false){
				return false;
			}
			return this.dispatchEvent(event);
		}
	}
}